package com.ruoyi.system.controller;

import java.util.List;

import com.ruoyi.api.system.domain.SysRegion;
import com.ruoyi.common.core.domain.Ztree;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.system.service.ISysRegionService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 行政区字典Controller
 * 
 * @author ruoyi
 * @date 2021-08-19
 */
@Controller
@RequestMapping("/system/region")
public class SysRegionController extends BaseController
{
    private String prefix = "system/region";

    @Autowired
    private ISysRegionService sysRegionService;

    @RequiresPermissions("system:region:view")
    @GetMapping()
    public String region()
    {
        return prefix + "/region";
    }

    /**
     * 选择单位树
     *
     */
    @GetMapping("/selectRegionTree")
    public String selectRegionTree()
    {
        return prefix + "/tree";
    }

    /**
     * 加载部门列表树
     */
    @GetMapping("/treeData")
    @ResponseBody
    public List<Ztree> treeData()
    {
        List<Ztree> ztrees = sysRegionService.selectRegionTree();
        return ztrees;
    }

    /**
     * 查询行政区字典列表
     */
    @RequiresPermissions("system:region:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysRegion sysRegion)
    {
        startPage();
        List<SysRegion> list = sysRegionService.selectSysRegionList(sysRegion);
        return getDataTable(list);
    }
}
